package com.example.xinli.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xinli.dao.XingdongjihuaMapper;
import com.example.xinli.dao.YingduijihuaMapper;
import com.example.xinli.domain.entity.Xingdongjihua;
import com.example.xinli.domain.entity.Yingduijihua;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ResponseBeanEnum;
import com.example.xinli.domain.vo.XingdongjihuaSubmitVo;
import com.example.xinli.domain.vo.YingduijihuaSubmitVo;
import com.example.xinli.service.IXingdongjihuaService;
import com.example.xinli.service.IYingduijihuaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class YingduijihuaServiceImpl extends ServiceImpl<YingduijihuaMapper, Yingduijihua> implements IYingduijihuaService {

    @Autowired
    YingduijihuaMapper yingduijihuaMapper;

    @Override
    public ResponseBean getAllUserYingduijihua(String userId) {
        QueryWrapper<Yingduijihua> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<Yingduijihua> yingduijihuaList = yingduijihuaMapper.selectList(queryWrapper);
        return ResponseBean.success(yingduijihuaList);
    }

    @Override
    public ResponseBean submitYingduijihua(YingduijihuaSubmitVo yingduijihuaSubmitVo) {
        Yingduijihua yingduijihua = new Yingduijihua();
        yingduijihua.setUserId(yingduijihuaSubmitVo.getUserId());
        yingduijihua.setDate(yingduijihuaSubmitVo.getDate());
        yingduijihua.setJihuaName(yingduijihuaSubmitVo.getJihuaName());
        yingduijihua.setQingjing(yingduijihuaSubmitVo.getQingjing());
        yingduijihua.setCelue(yingduijihuaSubmitVo.getCelue());
        yingduijihua.setDuanqi(yingduijihuaSubmitVo.getDuanqi());
        yingduijihua.setChangqi(yingduijihuaSubmitVo.getChangqi());
        yingduijihua.setRecordId(-1);

        int res = yingduijihuaMapper.insert(yingduijihua);
        if (res > 0) {
            return ResponseBean.success();
        }
        return ResponseBean.error(ResponseBeanEnum.ERROR);
    }
}

